home *** CD-ROM | disk | FTP | other *** search
Text File | 1997-02-13 | 29.1 KB | 990 lines | [TEXT/MPS ] |
- /*
- File: BindngH.cpp
-
- Contains: C++ Implementation for Binding Helper class.
-
- Owned by: Caia Grisar
-
- Copyright: © 1993 - 1996 by Apple Computer, Inc., all rights reserved.
-
- Change History (most recent first):
-
- <14> 11/21/96 RA Never use Apple::NoPart for AlphanumChoose
- <13> 10/18/96 RA 1398111: Substitution dialog should not
- appear for Apple's NoPart
- <12> 10/10/96 RA Moved ChangeKindAndEditor, ChangeEditor,
- IsNoPart and GetCurrentEditorForPart to
- BindingUtils.cpp
- <11> 10/7/96 RA 1343748: Store the preferred editor and its
- user string as a pair
- <10> 10/4/96 EL 1392459: do not set NoPart as the preferred
- editor.
- <9> 9/17/96 RA 1370339: NoPart should be replacable by
- third parties, added choose
- kODViewerOfLastResortKind
- <8> 6/27/96 RA 1361408: Compare against null viewer part
- handler instead of
- kODBlackBoxHandlerOfLastResort so NoPart
- does not get in the way of alphanum choose
- or editor over viewer preference.
- <7> 6/21/96 RA 1360591: Changed viewer NS type from object
- to value
- <6> 6/12/96 RA 1356993: Check permissions before writing
- out kODPropPreferredEditor
- <5> 6/6/96 EL 1335851: GetCurrentEditorForPart don't need
- to make a copy of Editor string. Forgot to
- check this in last time.
- <4> 6/4/96 EL 1335851: GetEditor now returns a copy, so
- GetCurrentEditorForPart don't need to make
- a copy.
- <3> 1/26/96 VL 1170098: Removed call to IsEditorLoaded
- because it unnecessarily loads and unloads
- the part library.
- <2> 1/8/96 CG 1299331 1.0.1: Substitution warning dlg
- nolonger displayed in background.
- <48> 10/24/95 TJ Included TempIter.h
- <47> 10/23/95 CG #1294762 GM: Out-of-memory on close forces
- close without saving changes
- #1295082 GM: Crash switching editor if lib
- can't load
- #1295186 GM: Failure in InitPartFromStorage
- doesn't abort editor switch
- #1295105 GM: Fail during Editor Change can
- leave Preferred Kind set incorrectly
- <46> 10/9/95 CC 1291425: Fixed logic in
- ChangeKindAndEditor.
- <45> 10/4/95 CG #1284324 GM: PartInfo dialog may display
- wrong editor.
- <44> 9/12/95 DM 1280020 FB1 part trans dlg mem leaks
- <43> 9/8/95 CG #1283252 FB1: Allocate memory for Editor
- string in NoPart case.
- <42> 9/8/95 TÇ 1281096 FB2:Many constants in ODTypesB
- without kOD prefix!
- <41> 9/7/95 CG #1262630 FB2: Bad warning when NoPart
- rebinds.
- <40> 8/30/95 CG #1244563 FB1:Missing editor needs
- explanatory alert
- #1215054 FB: Too many substitute editor
- dialog
- #1276989 FB:Leakage from SU::GetType calls
- <39> 8/12/95 TÇ 1276807 Opt./Bug: use StdTypIO routines for
- portable streaming & smaller footprint,
- 1276810 Binding writes to storage without
- checking permissions!
- <38> 8/8/95 jpa Fixed ChooseDirectEditorForKind, which was
- returning disposed pointers. [1275499]
- <37> 6/21/95 CC 1260937: BB: ODTypeListIterator must return
- copies of ODType values.
- <36> 6/19/95 VL 1170098: Set return result for
- GetPreferredEditorForPart to kODNULL if the
- operation fails.
- <35> 6/16/95 EL #1254926: Don't return an editor that does
- not exists.
- <34> 6/16/95 CC 1259719: Added ChangeEditor and
- ChangeKindAndEditor.
- <33> 5/18/95 CG #1249728 BB: BindingH.cpp needs to call
- StdTypIO routines for ISOStr
- #1249263 BB: BndNSUtl.cpp does not compile
- standalone.
- <32> 4/27/95 CC 1243813: Removed ShowAlert and
- BindingDialogFilter; replaced by ShowAlert
- in DlogUtil.
- <31> 4/26/95 CG 1210975 BB: 5$ Bugs need to be evaluatedand
- removed from Binding.
- <30> 4/26/95 CG 1210975 BB: 5$ Bugs need to be evaluated
- and removed from Binding.
- <29> 4/13/95 CG Removed obsolete #include.
- <28> 3/28/95 CG #1211901 BB: Binding methods check for
- null storage unit.
- <27> 2/16/95 CG #1213926 BB:binding respects preferred
- kinds. #1210975 BB: 5$ fixes.
- <26> 2/14/95 TJ Fixed copyright date.
- <25> 2/14/95 jpa Fixed GetContainerSuite to always return
- NULL on failure, and to use the
- SysPrefContainerSuites namespace. [1205141]
- <24> 2/2/95 CG #1195019: ValueNameSpace entries are now
- copied in and out instead of pointers being
- passed around.
- <23> 1/25/95 jpa Fixed no-prefs crashes [1214750]
- <22> 1/24/95 CG In GetContainerSuite now check return value
- of ValueNameSpaceGetEntry instead of return
- parameter. broke last build.
- <21> 1/23/95 CG #1195019: ValueNameSpace methods now take
- ODByteArray parameter instead of ODPtr.
- <20> 1/13/95 RR Removed include of ODTypesM.xh
- <19> 1/12/95 jpa Don't use obsolete Toolbox names. [1211211]
- <18> 1/10/95 CG #1201731: BB: Now get NoPart if a part
- can't be loaded because of an error.
- <17> 12/20/94 VL 1195012: Make Storage calls be
- marshallable.
- <16> 12/13/94 CG #1193522: Warning dialog displayed if
- automatic binding has occurred.
- <15> 10/7/94 CG #1184728: Broke NoPart with last fix!
- <14> 10/7/94 CG #1184728: Binding to another part that
- supports the same kind when original editor
- not found now works.
- <13> 9/9/94 CG 1182933: changed NoPart editor id.
- <12> 9/9/94 jpa Fixed IsEditorLoaded to call new
- ODClassExists rather than use SOM; this fix
- re-enables debugging of parts. [1182105]
- <11> 8/24/94 CG #1181622: Updated file ownership.
- <10> 8/17/94 CG #1181440 The View and EditorKinds name
- spaces were changed to be of type
- ODObjectNameSpace.
- <9> 7/29/94 CG NameSpace API changes.
- <8> 7/26/94 jpa Don't call InitObject from InitBinding.
- <7> 7/1/94 CG Changes to IsEditorLoaded.
- <6> 7/1/94 CG Added som calls to IsEditorLoaded.
- <5> 6/28/94 VL Use Translt.cpp.
- <4> 6/27/94 CG Moved IsEditorLoaded here from Prefs.
- Removed fEv.
- <3> 6/23/94 eeh oops....include EditrSet.h
- <2> 6/23/94 eeh remove ODEditorSetIterator and EditorSet
- <1> 6/20/94 CG first checked in
-
- To Do:
- In Progress:
-
- */
-
- #include <somcls.xh>
- #include <somcm.xh>
-
- #ifndef __ERRORS__
- #include <Errors.h>
- #endif
-
- #ifndef _BINDNGH_
- #include "BindngH.h"
- #endif
-
- #ifndef _EDITRSET_
- #include "EditrSet.h"
- #endif
-
- #ifndef _ODMEMORY_
- #include "ODMemory.h"
- #endif
-
- #ifndef SOM_ODStorageUnit_xh
- #include "StorageU.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdDefs_defined
- #include "StdDefs.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdProps_defined
- #include "StdProps.xh"
- #endif
-
- #ifndef SOM_Module_OpenDoc_StdTypes_defined
- #include "StdTypes.xh"
- #endif
-
- #ifndef _ODUTILS_
- #include "ODUtils.h"
- #endif
-
- #ifndef SOM_ODTranslation_xh
- #include "Translt.xh"
- #endif
-
- #ifndef _ODSESSN_
- #include "ODSessn.xh"
- #endif
-
- #ifndef SOM_ODValueNameSpace_xh
- #include "ValueNS.xh"
- #endif
-
- #ifndef SOM_ODObjectNameSpace_xh
- #include "ObjectNS.xh"
- #endif
-
- #ifndef _ORDCOLL_
- #include "OrdColl.h"
- #endif
-
- #ifndef SOM_ODNameSpaceManager_xh
- #include "NmSpcMg.xh"
- #endif
-
- #ifndef _EXCEPT_
- #include "Except.h"
- #endif
-
- #ifndef _PASCLSTR_
- #include "PasclStr.h"
- #endif
-
- #ifndef _ISOSTR_
- #include "ISOStr.h"
- #endif
-
- #ifndef SOM_Apple_NoPart_xh
- #include <NoPart.xh>
- #endif
-
- #ifndef SOM_ODTypeList_xh
- #include <TypeList.xh>
- #endif
-
- #ifndef SOM_ODTypeListIterator_xh
- #include <TypLsItr.xh>
- #endif
-
- #ifndef _BNDNSUTL_
- #include "BndNSUtl.h"
- #endif
-
- #ifndef _ODNEWOBJ_
- #include <ODNewObj.h>
- #endif
-
- #ifndef __DIALOGS__
- #include <Dialogs.h>
- #endif
-
- #ifndef SOM_ODWindowState_xh
- #include <WinStat.xh>
- #endif
-
- #ifndef SOM_ODWindow_xh
- #include <Window.xh>
- #endif
-
- #ifndef _USERSRCM_
- #include <UseRsrcM.h>
- #endif
-
- #ifndef _STORUTIL_
- #include <StorUtil.h>
- #endif
-
- #ifndef _BNDNGDEF_
- #include "BndngDef.h"
- #endif
-
- #ifndef SOM_ODFrame_xh
- #include <Frame.xh>
- #endif
-
- #ifndef _NMSPCUTL_
- #include <NmSpcUtl.h>
- #endif
-
- #ifndef SOM_ODDispatcher_xh
- #include <Disptch.xh>
- #endif
-
- #ifndef _DLOGUTIL_
- #include <DlogUtil.h>
- #endif
-
- #ifndef SOM_ODPartWrapper_xh
- #include <PartWrap.xh>
- #endif
-
- #ifndef _DOCUTILS_
- #include <DocUtils.h>
- #endif
-
- #ifndef _STDTYPIO_
- #include <StdTypIO.h>
- #endif
-
- #ifndef _INFOUTIL_
- #include "InfoUtil.h"
- #endif
-
- #ifndef _TEMPOBJ_
- #include <TempObj.h>
- #endif
-
- #ifndef _TEMPITER_
- #include "TempIter.h"
- #endif
-
- #ifndef SOM_ODBinding_xh
- #include <ODBindng.xh>
- #endif
-
- #ifndef _BARRAY_
- #include "BArray.h"
- #endif
-
- #ifndef _BINDINGUTILS_
- #include "BindingUtils.h"
- #endif
-
- #pragma segment Binding
-
- #undef LOGGING
- #define LOGGING 0
-
- //==============================================================================
- // Constants
- //==============================================================================
-
- #define kEditorSubstitutionList "EditorSubstitutions"
-
- //=========================================================================
- // Function Prototypes
- //=========================================================================
-
- ODStatic void ODPascal BindingNMResponse( NMRecPtr theNMRecPtr );
-
- ODStatic StringPtr BuildNotificationString(ODSShort strResourceID, Str255 catString, Str255 editorString);
-
- //==============================================================================
- // BindingNMResponse
- //==============================================================================
-
- ODStatic void ODPascal BindingNMResponse( NMRecPtr theNMRecPtr )
- {
- OSErr error = NMRemove(theNMRecPtr);
- }
-
- //------------------------------------------------------------------------------
- // BuildNotificationString
- //------------------------------------------------------------------------------
-
- ODStatic StringPtr BuildNotificationString(ODSShort strResourceID, Str255 catString, Str255 editorString)
- {
- Str255 msgStr;
-
- StringPtr result = kODNULL;
-
- ODSLong savedRefNum;
- BeginUsingLibraryResources(savedRefNum);
-
- ReplaceIntoString(strResourceID, catString, editorString, msgStr);
-
- if ( msgStr[0] > 0 )
- {
- ODULong ptrSize = msgStr[0]+1;
- result = (StringPtr) ODNewPtr(ptrSize);
- if ( result )
- ODBlockMove((ODPtr) &msgStr, (ODPtr) result, ptrSize);
- }
-
- EndUsingLibraryResources(savedRefNum);
-
- return result;
- }
-
- //==============================================================================
- // Class Binding
- //==============================================================================
-
- //------------------------------------------------------------------------------
- // Binding::Binding
- //------------------------------------------------------------------------------
- Binding::Binding()
- {
- fSession = (ODSession*) kODNULL;
- fSelf = (ODBinding*) kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // Binding::~Binding
- //------------------------------------------------------------------------------
- Binding::~Binding()
- {
- Environment* ev = somGetGlobalEnvironment ();
- ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(ev);
- nsm->DeleteNameSpace(ev, fSubstitutionList);
- if ( fNMResponseUPP != kODNULL )
- DisposeRoutineDescriptor(fNMResponseUPP);
-
- if ( fNMRecPtr )
- ODDisposePtr((ODPtr) fNMRecPtr->nmStr);
- ODDisposePtr(fNMRecPtr);
- }
-
- //------------------------------------------------------------------------------
- // Binding::InitBinding
- //------------------------------------------------------------------------------
- void Binding::InitBinding(ODSession* session )
- {
- Environment* ev = somGetGlobalEnvironment ();
-
- fSession = session;
- InitBindingNamespaceUtils(session);
- fSelf = session->GetBinding(ev);
-
- ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(ev);
-
- fSubstitutionList = (ODValueNameSpace*)nsm->CreateNameSpace(ev,
- (ODISOStr)kEditorSubstitutionList, kODNULL, 1, kODNSDataTypeODValue);
-
- fNMResponseUPP = NewNMProc(BindingNMResponse);
- fNMRecPtr = (NMRecPtr) ODNewPtr(sizeof(NMRec));
- THROW_IF_NULL(fNMRecPtr);
- fNMRecPtr->nmStr = kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // Binding::Purge
- //------------------------------------------------------------------------------
- ODSize Binding::Purge(ODSize size)
- {
- ODUnused(size);
- // The only memory that Binding has to purge is owned by NmSpcMgr and
- // is being purge from there.
- return 0;
- }
-
-
- //---------------------------------
- // Direct editor bindings
-
- //------------------------------------------------------------------------------
- // Binding::ChooseEditorForPart
- //------------------------------------------------------------------------------
- ODEditor Binding::ChooseEditorForPart(ODStorageUnit* thePartSU, ODType newKind )
- {
- ODEditor theChosenEditor = (ODEditor)kODNULL; ODVolatile( theChosenEditor );
- ODBoolean noPreferredEditorProp = kODFalse;
-
- TRY
- if (thePartSU)
- theChosenEditor = GetPreferredEditorForPart(thePartSU, &noPreferredEditorProp);
- if (theChosenEditor)
- {
- LOG("Using prefered editor %s",theChosenEditor);
- return theChosenEditor;
- }
-
- theChosenEditor = ChooseDirectEditorForPart(thePartSU, newKind);
-
- /*
- // NO AUTOMATIC TRANSLATION in v1
-
- if (!theChosenEditor && AutomaticTranslation())
- theChosenEditor = TranslateAndChooseEditorForPart(thePartSU);
- */
-
- if (!theChosenEditor)
- {
- WARN("Chosen editor is kODNULL ; returning NoPart");
-
- theChosenEditor = (ODEditor) ODNewPtrClear(
- sizeof(kODBlackBoxHandlerOfLastResort) + 1);
- ODBlockMove( kODBlackBoxHandlerOfLastResort,
- theChosenEditor, sizeof(kODBlackBoxHandlerOfLastResort) + 1 );
- }
- else
- {
- Environment* ev = somGetGlobalEnvironment ();
-
- LOG("Chosen editor is %s",theChosenEditor);
-
- if (thePartSU)
- {
-
- // This routine is a no-op if the ChoosenEditor is a
- // viewerOfLastResort or the draft has read only permissions.
- ODSetPreferredEditorProps(thePartSU,theChosenEditor);
-
- /*
- if ((!readOnlyStorage) && !ODISOStrEqual(theChosenEditor, kODBlackBoxHandlerOfLastResort))
- {
- ODSetISOStrProp(ev, thePartSU, kODPropPreferredEditor,
- kODEditor, theChosenEditor);
- }
- */
-
- TRY
- if (!noPreferredEditorProp && !IsNoPart(ev,theChosenEditor))
- this->SubstitutionWarning(theChosenEditor, thePartSU);
- ENDTRY
- CATCH_ALL
-
- }
- }
-
- CATCH_ALL
- ODDeleteObject( theChosenEditor );
- RERAISE;
- ENDTRY
-
- return theChosenEditor;
- }
-
- //------------------------------------------------------------------------------
- // Binding::TranslateAndChooseEditorForPart
- //------------------------------------------------------------------------------
-
- ODEditor Binding::TranslateAndChooseEditorForPart(ODStorageUnit* thePartSU)
- {
- ODUnused(thePartSU);
- return (ODEditor)kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // Binding::ChooseDirectEditorForPart
- //------------------------------------------------------------------------------
-
- ODEditor Binding::ChooseDirectEditorForPart(ODStorageUnit* thePartSU,
- ODType newKind )
- {
- // NOTE: This method does NOT check the preferred editor of the given part
-
- Environment* ev = somGetGlobalEnvironment ();
- ODEditor theEditor = kODNULL;
-
- if (thePartSU)
- {
- // Check for preferredKind property
- ODType preferredKind;
- if ((preferredKind = ODGetISOStrProp(ev, thePartSU,
- kODPropPreferredKind, kODISOStr, kODNULL, kODNULL))
- != kODNULL)
- {
- theEditor = ChooseDirectEditorForKind(preferredKind,thePartSU);
- ODDisposePtr(preferredKind);
- }
-
- if (theEditor)
- return theEditor;
- // Attempt to bind using the content values in their fidelity order
- for (ODValueIndex valueIndex = 1;
- thePartSU->Exists(ev, kODPropContents,(ODValueType)kODNULL,valueIndex)
- && (theEditor == kODNULL);
- valueIndex++)
- {
- thePartSU->Focus(ev, kODPropContents,kODPosSame,(ODValueType)kODNULL,
- valueIndex,kODPosSame);
- TempODValueType type = thePartSU->GetType(ev);
- theEditor = ChooseDirectEditorForKind(type,thePartSU);
- }
- if (theEditor)
- return theEditor;
- }
-
- if (newKind)
- theEditor = ChooseDirectEditorForKind(newKind,thePartSU);
-
- if (!theEditor)
- theEditor = ChooseDirectEditorForKind(kODViewerOfLastResortKind,thePartSU);
-
- if (theEditor)
- return theEditor;
- else
- return kODNULL;
- }
-
- //------------------------------------------------------------------------------
- // Binding::ChooseDirectEditorForKind
- //------------------------------------------------------------------------------
-
- ODEditor Binding::ChooseDirectEditorForKind(ODType aKind,
- ODStorageUnit* thePartSU)
- {
- ODEditor theEditor = kODNULL; ODVolatile( theEditor );
- EditorSet* editorSet = kODNULL; ODVolatile( editorSet );
- Environment* ev = somGetGlobalEnvironment ();
-
- if (!aKind )
- return theEditor;
-
- TRY
- ODNameSpaceManager* theNameSpaceManager = fSession->GetNameSpaceManager(ev);
-
- if (thePartSU)
- {
- EditorSet* theEditorSet = GetAllRestrictedEditorsForKind(thePartSU->
- GetDraft(ev),aKind);
- if (theEditorSet != kODNULL)
- {
- theEditor = AlphaNumChooseEditor(theEditorSet);
- SetSysPrefEditorForKind(theNameSpaceManager, aKind,theEditor);
- return theEditor;
- }
- }
-
- theEditor = GetSysPrefEditorForKind(theNameSpaceManager, aKind);
- if (theEditor && EditorExists(theEditor))
- return theEditor;
- else
- {
- ODDisposePtr( theEditor );
- theEditor = kODNULL;
- }
-
- ODTypeList* categories = GetCategoriesOfKind(theNameSpaceManager, aKind);
- if (categories)
- {
- ODBoolean editorFound = kODFalse;
- for (TempODTypeListIterator catItr(ev,categories);
- catItr.Current() && !editorFound;
- catItr.Next())
- {
- theEditor = GetSysPrefEditorForCategory(theNameSpaceManager,
- catItr.Current());
- editorFound = (theEditor &&
- EditorSupportsKind(theNameSpaceManager, theEditor,aKind) &&
- EditorExists(theEditor));
- }
- if (editorFound)
- return theEditor;
- else
- {
- ODDisposePtr( theEditor );
- theEditor = kODNULL;
- }
- }
-
- editorSet = new EditorSet;
- editorSet->InitEditorSet();
-
- if (GetAllEditorsForKind( theNameSpaceManager, aKind, editorSet ))
- {
- theEditor = AlphaNumChooseEditor(editorSet);
- if (EditorExists(theEditor)) {
- SetSysPrefEditorForKind(theNameSpaceManager, aKind,theEditor);
- theEditor = ODISOStrFromCStr(theEditor); // Duplicate the string!
- } else
- theEditor = kODNULL;
- }
-
- ODDeleteObject( editorSet );
- CATCH_ALL
- ODDeleteObject( editorSet );
- ODDisposePtr( theEditor );
- RERAISE;
- ENDTRY
-
- return theEditor;
- }
-
- //---------------------------------
- // Editor related utility methods
-
- //------------------------------------------------------------------------------
- // Binding::EditorExists
- //
- // lookup editor in editorkinds namespace and return kODTrue if it exists
- //------------------------------------------------------------------------------
-
- ODBoolean Binding::EditorExists(ODEditor editor)
- {
- Environment* ev = somGetGlobalEnvironment ();
- ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(ev);
-
- /* Try twice to find the editor. If the first search fails, re-synch the
- name-space (by hitting the disk and searching all available "Editors"
- folders) and try again. If the second search fails, give up. --jpa */
-
- /* ????? This could be slow if we are called many times in a row with
- genuinely nonexistent editors. If this turns out to be a real problem,
- one could keep around the time of last synching, and not synch more than
- once every five seconds. */
-
- ODBoolean synched = kODFalse;
- for( ;; ) {
- ODNameSpace* editorkindsNameSpace =
- fSession->GetNameSpaceManager(ev)->HasNameSpace( ev, kODEditorKinds );
-
- if ( editorkindsNameSpace
- && editorkindsNameSpace->Exists(ev, (ODISOStr)editor) )
- return kODTrue;
-
- if( !synched ) {
- synched = kODTrue;
- nsm->SynchNSTable(ev);
- continue;
- } else
- return kODFalse;
- }
- }
-
- //------------------------------------------------------------------------------
- // Binding::IsEditorLoaded
- //------------------------------------------------------------------------------
- ODBoolean Binding::IsEditorLoaded(ODEditor editor)
- {
- return ODClassExists(editor);
- }
-
- //------------------------------------------------------------------------------
- // Binding::GetPreferredEditorForPart
- //------------------------------------------------------------------------------
- ODEditor Binding::GetPreferredEditorForPart(ODStorageUnit* thePartSU,
- ODBoolean* noPreferredEditorProp)
- {
- // read preferred editor from thePartSU
- Environment* ev = somGetGlobalEnvironment ();
- ODEditor preferredEditor = kODNULL;
- if (thePartSU->Exists(ev, kODPropPreferredEditor,kODEditor,0))
- {
- ODULong size;
- preferredEditor = ODGetISOStrProp(ev, thePartSU,
- kODPropPreferredEditor, kODEditor, kODNULL, &size);
- if (preferredEditor)
- {
- if (EditorExists(preferredEditor))
- {
- *noPreferredEditorProp = kODFalse;
- } else {
- ODDisposePtr(preferredEditor);
- preferredEditor = kODNULL;
- // the prop exists in SU but is empty
- if (size == 0)
- *noPreferredEditorProp = kODTrue;
- }
- }
- }
- else
- {
- *noPreferredEditorProp = kODTrue;
- if (HAS_WRITE_ACCESS(thePartSU->GetDraft(ev)->GetPermissions(ev)))
- ODSUAddPropValue(ev, thePartSU, kODPropPreferredEditor, kODEditor);
- }
- return preferredEditor;
- }
-
-
- //------------------------------------------------------------------------------
- // Binding::GetKindsSupported
- //
- // lookup editor in editorkinds namespace and return kinds supported
- //------------------------------------------------------------------------------
-
- ODTypeList* Binding::GetKindsSupported(ODEditor editor)
- {
- ODTypeList* kindsList = kODNULL;
- Environment* ev = somGetGlobalEnvironment ();
-
- // get the editorkinds namespace
- ODObjectNameSpace* editorkindsNameSpace =
- (ODObjectNameSpace*)fSession->GetNameSpaceManager(ev)->HasNameSpace( ev,
- kODEditorKinds );
-
- if (editorkindsNameSpace)
- {
- // Lookup the kinds list by editor class ID
- if (editorkindsNameSpace->GetEntry( ev, (ODISOStr)editor,
- (ODObject**)&kindsList ))
- return kindsList;
- else
- return kODNULL;
- }
- return kindsList;
- }
-
- //------------------------------------------------------------------------------
- // Binding::AlphaNumChooseEditor
- //------------------------------------------------------------------------------
-
- ODEditor Binding::AlphaNumChooseEditor(EditorSet* editorSet)
- {
- // Note: We Alphanumchoose on ISO strings, not user strings so the winning
- // editor may be unpredictable to end users.
-
- // We "prime the pump" with a null viewer part handler that can never win an
- // alphanumeric choose. Previously NoPart (Apple::NoPart) could incorrectly
- // win over a viewer or editor whose name was further down in the alphabet.
-
- Environment* ev = somGetGlobalEnvironment();
-
- ODEditor bestHandler = (ODEditor)kNullViewerPartHandler;
-
- EditorSetIterator* eit = editorSet->CreateIterator();
-
- for (ODEditor handler = eit->First();
- eit->IsNotComplete();
- handler = eit->Next())
- {
- if (IsNoPart(ev, handler))
- handler = kNullViewerPartHandler; // use proxy instead of Apple::NoPart
-
- bestHandler = AlphaNumChooseAnEditorFromTwo(handler,bestHandler);
- }
- ODDeleteObject( eit );
-
- if (strcmp((char*)bestHandler,(char*)kNullViewerPartHandler)==0)
- bestHandler = kODBlackBoxHandlerOfLastResort; // Convert null viewer part handler to NoPart
-
- return bestHandler;
- }
-
- //------------------------------------------------------------------------------
- // Binding::AlphaNumChooseAnEditorFromTwo
- //------------------------------------------------------------------------------
-
- ODEditor Binding::AlphaNumChooseAnEditorFromTwo(ODEditor e1, ODEditor e2)
- {
- Environment* ev = somGetGlobalEnvironment ();
- ODValueNameSpace* theViewerNameSpace = ViewerNameSpace();
- TempODByteArrayStruct ignore;
- ODBoolean e1IsViewer = kODFalse;
- ODBoolean e2IsViewer = kODFalse;
-
- if (theViewerNameSpace)
- {
- e1IsViewer = theViewerNameSpace->GetEntry(ev, (ODISOStr)e1, ignore);
- e2IsViewer = theViewerNameSpace->GetEntry(ev, (ODISOStr)e2, ignore);
- }
-
- if (!e1IsViewer && e2IsViewer)
- return e1;
- else if (!e2IsViewer && e1IsViewer)
- return e2;
- else if (strcmp((char*)e1,(char*)e2)<=0)
- return e1;
- else
- return e2;
- }
-
- //------------------------------------------------------------------------------
- // Binding::DraftRestrictsEditors
- //------------------------------------------------------------------------------
-
- ODBoolean Binding::DraftRestrictsEditors(ODDraft* draft)
- {
- ODUnused(draft);
- // return whether or not restrictedEditors property exists
- return kODFalse;
- }
-
- //------------------------------------------------------------------------------
- // Binding::GetAllRestrictedEditorsForKind
- //------------------------------------------------------------------------------
-
- EditorSet* Binding::GetAllRestrictedEditorsForKind(ODDraft* draft, ODType kind)
- {
- ODUnused(draft);
- ODUnused(kind);
- // read and return restrictedEditors property of draftProperties
- return kODNULL;
- }
-
- //---------------------------------
- // Category and kind mappings
-
- //------------------------------------------------------------------------------
- // Binding::ViewerNameSpace
- //------------------------------------------------------------------------------
- ODValueNameSpace* Binding::ViewerNameSpace()
- {
- Environment* ev = somGetGlobalEnvironment ();
- return (ODValueNameSpace*)fSession->GetNameSpaceManager(ev)->HasNameSpace(
- ev, kODViewer );
- }
-
-
- //------------------------------------------------------------------------------
- // Binding::GetContainerSuite
- //------------------------------------------------------------------------------
-
- ODContainerSuite Binding::GetContainerSuite(ODContainerType containerType)
- {
- /* Two things can happen here. If containerType is the name of an actual
- container suite, we look it up in the ContainerSuite namespace and
- return the classname. But containerType might also be a constant
- indicating a type of default container suite (e.g. kODDefaultFileContainer)
- in which case we have to first look it up in the system-preferred
- ContainerSuite namespace to get the real container suite name, then
- do the lookup as above to get the classname. */
-
- ODContainerSuite theContainerSuite;
-
- // First look it up in the ContainerSuite namespace:
- theContainerSuite = ValueNameSpaceGetString(fSession,kODContainerSuite,containerType);
- if( !theContainerSuite ) {
- ODContainerSuite realType;
- ODBoolean isDefault = kODFalse;
- // Not found, look it up in the System-preferred Container Suites namespace:
- realType = ValueNameSpaceGetString(fSession,kODSysPrefContainerSuites,containerType);
- if( !realType ) {
- // Not found there either, check some hardcoded defaults:
- isDefault = kODTrue;
- if( ODISOStrEqual(containerType,kODDefaultMemoryContainer) )
- realType = kODBentoMemoryContainer;
- else if( ODISOStrEqual(containerType,kODDefaultFileContainer) )
- realType = kODBentoFileContainer;
- }
- if( realType ) {
- // Now that we have a real containerType, look it up in ContainerSuite:
- theContainerSuite = ValueNameSpaceGetString(fSession,kODContainerSuite,realType);
- if( !isDefault )
- ODDisposePtr(realType);
- }
- }
- return theContainerSuite;
- }
-
- //------------------------------------------------------------------------------
- // Binding::SubstitutionWarning
- //------------------------------------------------------------------------------
-
- void Binding::SubstitutionWarning(ODEditor theEditor, ODStorageUnit* thePartSU)
- {
- Environment* ev = somGetGlobalEnvironment ();
-
- ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(ev);
- TempODIText category = ODGetCatFromPartSU( ev, thePartSU, nsm); // DMc: temp to ensure it's deleted
- TempODISOStr theCategory = (ODISOStr)ODNewPtrClear(GetITextStringLength(category)+1);
- GetITextCString( category, (char*)theCategory );
-
- if (!NotifiedSubstitutions(theEditor, theCategory))
- {
- ODIText* editorUserString = kODNULL;
- Str255 editorString = "\p";
- Str255 catString = "\p";
-
- GetITextPString( category, catString );
-
- GetUserEditorFromEditor( nsm, theEditor, &editorUserString );
- TempODIText tempEditorUserString = editorUserString; // DMc: ensure it's deleted
- GetITextPString( editorUserString, editorString );
-
- NMRemove(fNMRecPtr); // ensure not already queued
- fNMRecPtr->qType = nmType;
- fNMRecPtr->nmMark = 0;
- fNMRecPtr->nmIcon = nil;
- fNMRecPtr->nmSound = nil;
- ODDisposePtr((ODPtr) fNMRecPtr->nmStr);
- fNMRecPtr->nmStr = BuildNotificationString(kBindingWarning, catString, editorString);
- fNMRecPtr->nmResp = fNMResponseUPP;
- ODError error = NMInstall(fNMRecPtr);
-
- if (fSubstitutionList)
- {
- ValueNameSpaceRegister(fSubstitutionList, ev, (ODISOStr)theCategory,
- (ODPtr)theEditor, ODISOStrLength(theEditor) + 1);
- }
- }
- }
-
-
- //------------------------------------------------------------------------------
- // Binding::NotifiedSubstitutions
- //------------------------------------------------------------------------------
-
- ODBoolean Binding::NotifiedSubstitutions(ODEditor theEditor, ODISOStr theCategory)
- {
- Environment* ev = somGetGlobalEnvironment ();
- ODNameSpaceManager *nsm = fSession->GetNameSpaceManager(ev);
-
- ODBoolean subAlreadyNotified = kODFalse;
-
- if (fSubstitutionList)
- {
- // Lookup the substitutionList by editor class ID
- ODISOStr editorSub = ValueNameSpaceGetString(fSession,
- kEditorSubstitutionList, theCategory);
- //WARN("ValueNameSpaceGetString returned '%s'", editorSub);
- if (ODISOStrEqual(editorSub, theEditor))
- subAlreadyNotified = kODTrue;
-
- ODDisposePtr( editorSub );
- }
-
- return subAlreadyNotified;
- }
-
-